Skip to content

perf(swift): optimize swift serialization performance - #3921

Merged
chaokunyang merged 10 commits into
apache:mainfrom
chaokunyang:optimize_swift_perf
Aug 4, 2026
Merged

perf(swift): optimize swift serialization performance#3921
chaokunyang merged 10 commits into
apache:mainfrom
chaokunyang:optimize_swift_perf

Conversation

@chaokunyang

@chaokunyang chaokunyang commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Why?

Swift's dynamic exclusivity checks and generic collection/String paths add measurable overhead to
serialization and deserialization, especially for small structs and collection-heavy objects.

What does this PR do?

  • Removes dynamic exclusivity checks from synchronous ByteBuffer state access.
  • Specializes packed primitive-array reads and avoids zero-initializing destination arrays.
  • Accelerates ASCII String detection with eight-byte checks while preserving UTF-8 validation.
  • Adds a direct fast path for non-null Array elements.
  • Uses the TypeMeta header hash directly for exact-schema compatible reads.
  • Refreshes the Swift benchmark report and throughput plot.

Related issues

Closes #3460

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: yes / no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.
  • If yes, my PR description includes the required ai_review summary and screenshot evidence or equivalent persisted links of the final clean AI review results from both fresh reviewers described in AI_POLICY.md, the Fory-guided reviewer and the independent general reviewer, on the current PR diff or current HEAD after the latest code changes.

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

Environment: Apple Swift 6.2.1. The complete benchmark used three seconds per case:

cd benchmarks/swift
./run.sh
Datatype Operation Fory ops/s Protobuf ops/s JSON ops/s
NumericStruct Serialize 14,759,606 7,572,190 481,278
NumericStruct Deserialize 18,155,795 7,317,942 377,802
Sample Serialize 5,633,231 1,380,130 102,372
Sample Deserialize 1,509,740 916,626 52,897
MediaContent Serialize 2,987,821 784,863 111,200
MediaContent Deserialize 1,072,345 549,726 97,799
NumericStructList Serialize 5,515,769 1,093,924 93,635
NumericStructList Deserialize 2,598,609 746,527 76,161
SampleList Serialize 1,201,868 220,772 20,772
SampleList Deserialize 286,949 161,192 10,777
MediaContentList Serialize 657,276 118,004 22,744
MediaContentList Deserialize 215,726 99,445 19,521

@chaokunyang chaokunyang changed the title perf(swift): remove buffer storage exclusivity checks perf(swift): optimize swift serialization performance Aug 4, 2026
@chaokunyang
chaokunyang merged commit 5eb14cd into apache:main Aug 4, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Swift] Reduce swift_beginAccess cost to optimize performance

3 participants